package com.gis.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gis.dao.LostDao;
import com.gis.dto.LostDto;
import com.gis.util.PageResult;
import com.gis.util.ResponseUtil;

import cn.hutool.core.util.StrUtil;


/**
 * 分页查询寻物启事
 * @author Administrator
 *
 */
@WebServlet("/lost/page")
public class LostPageServlet extends HttpServlet {
	LostDao lostDao = LostDao.getInstance();

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Map<String, Object> params = new HashMap<String, Object>();
		
		// easyUI分页时 默认使用的参数是 page/rows 来表示页码和行数 而返回值也必须使用total/rows 其中total表示总行数 而rows表示返回集合数组
		String pageSize = req.getParameter("rows");
		if(pageSize == null) {
			pageSize = "5";
		}
		String pageNum = req.getParameter("page");
		if(pageNum == null) {
			pageNum = "1";
		}
		
		String goodsTypeId = req.getParameter("goodsTypeId");
		if (StrUtil.isNotBlank(goodsTypeId)) {
			params.put("goodsTypeId", goodsTypeId);
		}
		String startDate = req.getParameter("startDate");
		if (StrUtil.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		String endDate = req.getParameter("endDate");
		if(StrUtil.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		Integer size = Integer.parseInt(pageSize);
		Integer num = Integer.parseInt(pageNum);
		params.put("offset", (num - 1) * size);
		params.put("rows", size);
		PageResult<LostDto> pageResult = lostDao.page(params);
		
		ResponseUtil.writePage(resp, pageResult);
	}
	
	
	
}
